<template>
  <div class="container">
    <h1>人员列表</h1>
    <h1 style="color: red">Count组件求和为{{ sum }}</h1>
    <input type="text" placeholder="请输入人员姓名" v-model="name" />
    <button @click="addPerson">点击确认</button>
    <ul>
      <li v-for="p in person" :key="p.id">{{ p.name }}</li>
    </ul>
  </div>
</template>

<script>
import { nanoid } from "nanoid";
export default {
  name: "Person",
  data() {
    return {
      name: "",
    };
  },
  computed: {
    person() {
      return this.$store.state.persons;
    },
    sum() {
      return this.$store.state.sum;
    },
  },
  components: {},
  methods: {
    addPerson() {
      const personObj = { id: nanoid(), name: this.name };
      this.$store.commit("addPerson", personObj);
      this.name = "";
    },
  },
};
</script>

